package mware_lib.communication;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.Socket;

public class ObjectStream {
	
    
    private ObjectOutputStream oos;
    private ObjectInputStream ois;
    private Socket sock;
    
    public ObjectStream(Socket sock) throws IOException{
        InputStream in = sock.getInputStream();
        OutputStream out = sock.getOutputStream();
        this.oos = new ObjectOutputStream(out);
        this.ois = new ObjectInputStream(in);
        this.sock = sock;
    }
    
    public void send(Object object) throws IOException{
        this.oos.writeObject(object);
    }
    
    public Object receive() throws IOException, ClassNotFoundException{
        return this.ois.readObject();
    }
    
    public void closeSocket() throws IOException{
        this.sock.close();
    }

}

